\hypertarget{group__nxbot__sonar}{
\section{SONAR Library}
\label{group__nxbot__sonar}\index{SONAR Library@{SONAR Library}}
}


SONAR library for reading SRF02 sonar-\/modules, connected via serial communication.  


\subsection*{Defines}
\begin{DoxyCompactItemize}
\item 
\#define \hyperlink{group__nxbot__sonar_ga6612dda55afa526ffb06f9607a2365d3}{SONAR\_\-STATE0\_\-REQ}~0
\begin{DoxyCompactList}\small\item\em State 0 of state-\/machine for reading distance values. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sonar_gabe57d815b133ba26dc9b0c531cfb8b1d}{SONAR\_\-STATE1\_\-1B}~1
\begin{DoxyCompactList}\small\item\em State 1 of state-\/machine for reading distance values. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sonar_ga05a9e87c82bc8a7686fb22f9611e0d77}{SONAR\_\-STATE2\_\-2B}~2
\begin{DoxyCompactList}\small\item\em State 2 of state-\/machine for reading distance values. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sonar_ga4acc6bf798541cb73c8454a03ce200a2}{SONAR\_\-READ\_\-READY}~0
\begin{DoxyCompactList}\small\item\em A distance-\/value has been correctly received. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sonar_ga5a93e5d8a1dac3bfb9e9cca3e7db09b9}{SONAR\_\-READ\_\-NOT\_\-READY}~1
\begin{DoxyCompactList}\small\item\em No distance-\/value has been yet completely received. \item\end{DoxyCompactList}\item 
\#define \hyperlink{group__nxbot__sonar_gae988a06397acc99246fc41524dd5e840}{SONAR\_\-INCH}~0
\item 
\#define \hyperlink{group__nxbot__sonar_gaddc16b864a6ec50a7b33c71a8bdc9829}{SONAR\_\-CM}~1
\item 
\#define \hyperlink{group__nxbot__sonar_ga8db188f21a03c242ce3c99caff9d2f70}{SONAR\_\-US}~2
\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \hyperlink{group__nxbot__sonar_ga97fb7cc76026e9c3b77485e8184927fe}{sonar\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Hardware initialization of the sonar module. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__sonar_ga9d697cf1169998e8a706c7edd4e7b42d}{sonar\_\-cleanBuffer} (void)
\begin{DoxyCompactList}\small\item\em Cleans uart stack. \item\end{DoxyCompactList}\item 
void \hyperlink{group__nxbot__sonar_ga83a31a2ecf7761fe81629f18350be1dc}{sonar\_\-write} (unsigned char sonarNum, unsigned char units)
\begin{DoxyCompactList}\small\item\em Sends command to desired SRF02 module for distance measuring. \item\end{DoxyCompactList}\item 
unsigned char \hyperlink{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{sonar\_\-read} (unsigned char sonarNum, unsigned int $\ast$val, char newState)
\begin{DoxyCompactList}\small\item\em Sends command to desired SRF02 module for distance reading. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
SONAR library for reading SRF02 sonar-\/modules, connected via serial communication. 
\begin{DoxyCode}
 #include <sonar.h> 
\end{DoxyCode}
 This module uses UART0 of the ATmega1281 microcontroller for communicating with the SRF02 modules. It can be configured for 3 to 8 SRF02 modules, all sharing the same serial connection. It is necessary to configure different directions for each module. This library is not an interrupt-\/driven module, but, as it depends on uart configuration, which is indeed an interrupt-\/driven module, it is necessary to enable interrupts by using the sei() function. 

\subsection{Define Documentation}
\hypertarget{group__nxbot__sonar_gaddc16b864a6ec50a7b33c71a8bdc9829}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-CM@{SONAR\_\-CM}}
\index{SONAR\_\-CM@{SONAR\_\-CM}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-CM}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-CM~1}}
\label{group__nxbot__sonar_gaddc16b864a6ec50a7b33c71a8bdc9829}
\hypertarget{group__nxbot__sonar_gae988a06397acc99246fc41524dd5e840}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-INCH@{SONAR\_\-INCH}}
\index{SONAR\_\-INCH@{SONAR\_\-INCH}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-INCH}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-INCH~0}}
\label{group__nxbot__sonar_gae988a06397acc99246fc41524dd5e840}
\hypertarget{group__nxbot__sonar_ga5a93e5d8a1dac3bfb9e9cca3e7db09b9}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-READ\_\-NOT\_\-READY@{SONAR\_\-READ\_\-NOT\_\-READY}}
\index{SONAR\_\-READ\_\-NOT\_\-READY@{SONAR\_\-READ\_\-NOT\_\-READY}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-READ\_\-NOT\_\-READY}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-READ\_\-NOT\_\-READY~1}}
\label{group__nxbot__sonar_ga5a93e5d8a1dac3bfb9e9cca3e7db09b9}


No distance-\/value has been yet completely received. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{sonar\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sonar_ga4acc6bf798541cb73c8454a03ce200a2}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-READ\_\-READY@{SONAR\_\-READ\_\-READY}}
\index{SONAR\_\-READ\_\-READY@{SONAR\_\-READ\_\-READY}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-READ\_\-READY}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-READ\_\-READY~0}}
\label{group__nxbot__sonar_ga4acc6bf798541cb73c8454a03ce200a2}


A distance-\/value has been correctly received. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{sonar\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sonar_ga6612dda55afa526ffb06f9607a2365d3}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-STATE0\_\-REQ@{SONAR\_\-STATE0\_\-REQ}}
\index{SONAR\_\-STATE0\_\-REQ@{SONAR\_\-STATE0\_\-REQ}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-STATE0\_\-REQ}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-STATE0\_\-REQ~0}}
\label{group__nxbot__sonar_ga6612dda55afa526ffb06f9607a2365d3}


State 0 of state-\/machine for reading distance values. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{sonar\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sonar_gabe57d815b133ba26dc9b0c531cfb8b1d}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-STATE1\_\-1B@{SONAR\_\-STATE1\_\-1B}}
\index{SONAR\_\-STATE1\_\-1B@{SONAR\_\-STATE1\_\-1B}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-STATE1\_\-1B}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-STATE1\_\-1B~1}}
\label{group__nxbot__sonar_gabe57d815b133ba26dc9b0c531cfb8b1d}


State 1 of state-\/machine for reading distance values. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{sonar\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sonar_ga05a9e87c82bc8a7686fb22f9611e0d77}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-STATE2\_\-2B@{SONAR\_\-STATE2\_\-2B}}
\index{SONAR\_\-STATE2\_\-2B@{SONAR\_\-STATE2\_\-2B}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-STATE2\_\-2B}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-STATE2\_\-2B~2}}
\label{group__nxbot__sonar_ga05a9e87c82bc8a7686fb22f9611e0d77}


State 2 of state-\/machine for reading distance values. 

\begin{DoxySeeAlso}{See also}
\hyperlink{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{sonar\_\-read} 
\end{DoxySeeAlso}
\hypertarget{group__nxbot__sonar_ga8db188f21a03c242ce3c99caff9d2f70}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!SONAR\_\-US@{SONAR\_\-US}}
\index{SONAR\_\-US@{SONAR\_\-US}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{SONAR\_\-US}]{\setlength{\rightskip}{0pt plus 5cm}\#define SONAR\_\-US~2}}
\label{group__nxbot__sonar_ga8db188f21a03c242ce3c99caff9d2f70}


\subsection{Function Documentation}
\hypertarget{group__nxbot__sonar_ga9d697cf1169998e8a706c7edd4e7b42d}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!sonar\_\-cleanBuffer@{sonar\_\-cleanBuffer}}
\index{sonar\_\-cleanBuffer@{sonar\_\-cleanBuffer}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{sonar\_\-cleanBuffer}]{\setlength{\rightskip}{0pt plus 5cm}void sonar\_\-cleanBuffer (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sonar_ga9d697cf1169998e8a706c7edd4e7b42d}


Cleans uart stack. 

Normally used when a valid reading has been made. As the SRF02 does not implement any protocol or datagram for sending the reading, this function is useful in order to avoid reading mistakes between multiple modules. \hypertarget{group__nxbot__sonar_ga97fb7cc76026e9c3b77485e8184927fe}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!sonar\_\-init@{sonar\_\-init}}
\index{sonar\_\-init@{sonar\_\-init}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{sonar\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void sonar\_\-init (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sonar_ga97fb7cc76026e9c3b77485e8184927fe}


Hardware initialization of the sonar module. 

Configures UART0 hardware in order to send and receive bytes via this interface. \hypertarget{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!sonar\_\-read@{sonar\_\-read}}
\index{sonar\_\-read@{sonar\_\-read}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{sonar\_\-read}]{\setlength{\rightskip}{0pt plus 5cm}unsigned char sonar\_\-read (
\begin{DoxyParamCaption}
\item[{unsigned char}]{sonarNum, }
\item[{unsigned int $\ast$}]{val, }
\item[{char}]{newState}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sonar_gaad6f525a621b2b79e529ab1da57bb692}


Sends command to desired SRF02 module for distance reading. 

It sends command 0x5E for returning the distance reading of the desired SRF02 sensor. This function implements a state machine for non-\/blocking calls. 
\begin{DoxyParams}{Parameters}
{\em sonarNum} & Desired SRF02 module. Use SONAR\_\-(ANGLE) constants for readings, e.g. SONAR\_\-45N. \\
\hline
{\em val} & Pointer where the reading will be saved.  For cases where the state-\/machine has to be resetted, use this parameter, with one of the SONAR\_\-STATE($\ast$) constants, normalle SONAR\_\-STATE0\_\-REQ is used. When not interested in resetting or setting the state-\/machine, use -\/1. \\
\hline
\end{DoxyParams}
\hypertarget{group__nxbot__sonar_ga83a31a2ecf7761fe81629f18350be1dc}{
\index{nxbot\_\-sonar@{nxbot\_\-sonar}!sonar\_\-write@{sonar\_\-write}}
\index{sonar\_\-write@{sonar\_\-write}!nxbot_sonar@{nxbot\_\-sonar}}
\subsubsection[{sonar\_\-write}]{\setlength{\rightskip}{0pt plus 5cm}void sonar\_\-write (
\begin{DoxyParamCaption}
\item[{unsigned char}]{sonarNum, }
\item[{unsigned char}]{units}
\end{DoxyParamCaption}
)}}
\label{group__nxbot__sonar_ga83a31a2ecf7761fe81629f18350be1dc}


Sends command to desired SRF02 module for distance measuring. 

It sends command 0x51 for distance measuring by the desired SRF02 sensor. 
\begin{DoxyParams}{Parameters}
{\em sonarNum} & Desired SRF02 module. Use SONAR\_\-(ANGLE) constants for readings, e.g. SONAR\_\-45N. \\
\hline
{\em units} & The desired units for the reading. Options are: SONAR\_\-INCH, SONAR\_\-CM, SONAR\_\-US \\
\hline
\end{DoxyParams}
